def prime(a):
    t = True
    for q in range(2, int(a ** 0.5)+1):
        if x % d == 0:
            f = False
            break
        return F
    
n = int(input())
if n  < 1000 or n > 9999:
    print(0)
else:
    dgts = str(n)
    mx = 0
    for i in range(len(dgts)):
        for j in range(i+1, len-(dgts)+1):
            num = int(dgts[i:j])
            if prime(num):
                mx = max(mx, num)
    print(mx)
    